//
//  SettingViewController.m
//  HYSmileiOS
//
//  Created by SMC-MAC on 16/5/31.
//  Copyright © 2016年 heyou. All rights reserved.
//

#import "SettingViewController.h"

#define ITEM_CLEAR_CACHE    @"ITEM_CLEAR_CACHE"
#define ITEM_RECOMMEND      @"推荐给好友"
#define ITEM_VERSION        @"ITEM_VERSION"
#define ITEM_ABOUT_US       @"关于我们"

@interface SettingViewController () {
    
}
@property (strong, nonatomic) NSArray *mList;

@end

@implementation SettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    [self prepareData];
    [self setupTableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -- prepare data
- (void)prepareData {
    NSArray *ary = @[ITEM_CLEAR_CACHE, ITEM_RECOMMEND, ITEM_VERSION, ITEM_ABOUT_US];
    self.mList = ary;
}

#pragma mark - setup tableview
- (void)setupTableView {
    // 注册自定义XIB
    self.tableView.tableFooterView = [UIView new];
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.mList.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    CGFloat height = 0.0f;
    
    height = MAX(height, 45.0f);
    return height;
}

#pragma mark -- config tableview
- (void)configCell:(UITableViewCell*)cell forIndex:(NSIndexPath*)indexPath {
    NSString *title = [self.mList objectAtIndex:indexPath.row];
    if ([title isEqualToString:ITEM_CLEAR_CACHE]) {
        NSInteger num = 123;
        title = [NSString stringWithFormat:@"清除缓存（已使用%ldM）", num];
    } else if ([title isEqualToString:ITEM_VERSION]) {
        title = [NSString stringWithFormat:@"当前版本：%@", @"1.0.1"];
    } else {
        
    }
    cell.textLabel.text = title;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = nil;
    
    NSString *identifier = @"ABOUT_ITEM_CELL";
    cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    
    // Configure the cell...
    [self configCell:cell forIndex:indexPath];
    
    return cell;
}

#pragma mark -- table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    NSString *title = [self.mList objectAtIndex:indexPath.row];
    NSLog(@"select %@", title);
    if ([title isEqualToString:ITEM_CLEAR_CACHE]) {
        
    } else if ([title isEqualToString:ITEM_RECOMMEND]) {
        
    } else if ([title isEqualToString:ITEM_VERSION]) {
        
    } else if ([title isEqualToString:ITEM_ABOUT_US]) {
        
    } else {
        
    }
}

@end
